package com.aos.erp.manager.rest.student;


import com.aos.erp.common.bean.PageBean;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.manager.model.student.ro.SelectStudentRo;
import com.aos.erp.manager.model.student.vo.StudentAllVo;
import com.aos.erp.manager.service.student.StudentService;
import com.aos.erp.manager.util.TimeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 学员信息表 前端控制器
 * </p>
 *
 * @author chb
 * @since 2018-10-31
 */
@RestController
@RequestMapping("/api/student")
@Api(tags = {"学员管理"})
public class StudentController {


    @Autowired
    private StudentService studentService ;

    @GetMapping("/getStudentAll")
    @ApiOperation(value = "学员所有信息查询")
    public ResultEntity<PageBean<StudentAllVo>> getStudentAll(SelectStudentRo ro){
        ro.setTimeStartName(TimeUtils.start(ro.getTimeStart()));
        ro.setTimeEddName(TimeUtils.edd(ro.getTimeEdd()));
        try {
            PageBean<StudentAllVo> student=studentService.queryByPage(ro);
            return ResultEntity.success(student);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("学员信息查询失败!");
        }
    }

    @GetMapping("/getStudentById")
    @ApiOperation(value = "单个学员信息查询", authorizations = @Authorization("TOKEN"))
    public ResultEntity<StudentAllVo> getStudentById(@RequestParam(value = "studentId")Long studentId){
        try {
            StudentAllVo student=studentService.queryObject(studentId);
            return ResultEntity.success(student);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed("学员信息查询失败!");
        }
    }
}

